
package org.apache.ocean;

import org.apache.commons.lang.*;
import org.apache.commons.io.*;
import java.util.*;
import java.io.*;

/**
 *
 * @author jasonr
 */
public class ExternalProcess {
  public String cmd = null;
  public Integer exitValue = null;
  public String stdout = null;
  
  public ExternalProcess(String cmd) throws Exception {
    this.cmd = cmd;
    List cmdList = Arrays.asList(StringUtils.splitByWholeSeparator(cmd, null));
    
    ProcessBuilder processBuilder = new ProcessBuilder(cmdList);
    processBuilder.redirectErrorStream(true);
    
    Process process = processBuilder.start();
    stdout = IOUtils.toString(process.getInputStream());
    exitValue = process.waitFor();
  }
  
  public String toString() {
    return "cmd: "+cmd+" exit: "+exitValue+" stdout: "+stdout;
  }
}
